<template>
  <div>
    <van-form @submit="onSubmit">
      <van-cell-group inset>
        <van-field v-model="username"
                   name="用户名"
                   label="用户名"
                   placeholder="用户名"
                   :rules="[{ required: true, message: '请填写用户名' }]" />
        <van-field v-model="password"
                   type="password"
                   name="密码"
                   label="密码"
                   placeholder="密码"
                   :rules="[{ required: true, message: '请填写密码' }]" />
      </van-cell-group>
      <div style="margin: 16px;">
        <van-button round
                    block
                    type="primary"
                    native-type="submit">
          提交
        </van-button>
      </div>
    </van-form>
  </div>
</template>

<script>

// 引入组件
import { Dialog } from 'vant'
import http from '../api/http.js'

export default {
  name: 'vant',
  data () {
    return {
      login_form: {
        username: 'admin',
        password: 'admin123',
        rememberMe: 'true',
        isMobile: ''
      }
    }
  },
  methods: {
    login () {
      let params = { 'username': 'admin', 'password': 'admin123', 'rememberMe': 'true', 'isMobile': '' }
      http.fetchPost('/sys/login', params).then((data) => {
        Dialog.alert({
          title: '标题',
          message: data.data.data
        }).then(() => {
          // on close
        })
        console.log(data.data.data)
        this.$router.push({ path: '/mint' })
        // this.base.token = data.data.token
        // console.log("this.base.tokenthis.base.token",this.base.token)
        // this.indexPost2(this.rres)
      }).catch(err => {
        console.log(err)
      }
      )
    },
    login2 () {
      // let params = { username: 'admin', password: 'admin123', rememberMe: 'true' }
      // let params = JSON.stringify(jsonStr)
      // console.log(JSON.stringify(params))
      http.fetchPost('/sys/login2', this.login_form).then((data) => {
        Dialog.alert({
          title: '标题',
          message: data.data.data
        }).then(() => {
          // on close
        })
        console.log(data.data.data)
        // this.$router.push({ path: '/mint' })
        // this.base.token = data.data.token
        // console.log("this.base.tokenthis.base.token",this.base.token)
        // this.indexPost2(this.rres)
      }).catch(err => {
        console.log(err)
      }
      )
    }
  }
}
</script>
